package com.runshu.newsmartark.mvp.presenter;




import com.runshu.newsmartark.mvp.contract.BaseContract;
import com.runshu.newsmartark.network.netbean.ResponseBean;
import com.runshu.newsmartark.network.netinterface.BaseCallBack;

import java.util.Map;

/**
 * <pre>
 *     Created by yyd
 *     desc   : BasePresenter基类
 *     version: 1.0   初始化
 *     params:
 *  <pre>
 */

public class BasePresenter implements BaseContract.BasePresenter {
    public BaseContract.BaseModel mModel;
    public BaseContract.BaseView mView;

    public BasePresenter(BaseContract.BaseModel mModel, BaseContract.BaseView mView) {
        this.mModel = mModel;
        this.mView = mView;
    }


    @Override
    public void initDataFromServer(String url, Map<String, Object> params, Class clz, int beanType) {
        mModel.initDataFromServer(url, params, clz, beanType, new BaseCallBack() {
            @Override
            public void onRequesting() {
                mView.onLoading();
            }

            @Override
            public void onSuccess(ResponseBean data) {
                mView.onSuccess(data);
            }

            @Override
            public void onError(ResponseBean msg) {
                mView.onFailure(msg);
            }

            @Override
            public void onErrorForOthers(ResponseBean msg) {
                mView.onFailure(msg);
            }
        });
    }

    @Override
    public void initDataFromServerGet(String url, Map<String, String> params, Class clz, int beanType) {
        mModel.initDataFromServerGet(url, params, clz, beanType, new BaseCallBack() {
            @Override
            public void onRequesting() {
                mView.onLoading();
            }

            @Override
            public void onSuccess(ResponseBean data) {
                mView.onSuccess(data);
            }

            @Override
            public void onError(ResponseBean msg) {
                mView.onFailure(msg);
            }

            @Override
            public void onErrorForOthers(ResponseBean msg) {
                mView.onFailure(msg);
            }
        });
    }
}
